package fightplan.actions;

import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JTable;

@SuppressWarnings("serial")
public class DeselectAllAction extends AbstractAction {

	private Component component;

	public DeselectAllAction(Component component) {
		super("Selektion aufheben");
		this.component = component;
	}

	public void actionPerformed(ActionEvent e) {
		deselect(component);
	}

	private void deselect(Component component) {
		if (!component.isEnabled() || !component.isShowing())
			return;
		if (component instanceof JTable) {
			((JTable) component).clearSelection();
			((JTable) component).removeEditor();
		}
		if (component instanceof Container) {
			Container container = (Container) component;
			for (Component child : container.getComponents()) {
				deselect(child);
			}
		}
	}

}
